package com.xiashitech.apiservice.job;

import com.xiashitech.apiservice.job.base.XSQuartzJobBean;
import com.xiashitech.apiservice.service.IPushHistroyService;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
public class PushDelete {
    @Component
    class PushJob extends XSQuartzJobBean {
        private IPushHistroyService pushHistroyService;

        @Autowired
        public PushJob(IPushHistroyService pushHistroyService) {
            this.pushHistroyService = pushHistroyService;
        }

        @Override
        protected void xsExecuteInternal(JobExecutionContext context) throws JobExecutionException {
            //System.out.println("pushJob delete execute");
            int i = pushHistroyService.deleteHistory();

        }
    }

    @Bean
    public JobDetail jobDetail() {
        JobDetail jobDetail = JobBuilder.newJob(PushJob.class)
                .withIdentity("pushJob_delete", "pushJob_delete")
                .storeDurably()
                .build();
        return jobDetail;
    }

    @Bean
    public Trigger trigger() {
        Trigger trigger = TriggerBuilder.newTrigger()
                .forJob(jobDetail())
                .withIdentity("pushJob_delete", "pushJob_delete")
                .startNow()
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ?"))
                .build();
        return trigger;
    }


}
